/*
 *  GRUB  --  GRand Unified Bootloader
 *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software Foundation, Inc.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */
#include "grub4dos.h"

int GRUB = 0x42555247;/* this is needed, see the following comment. */
/* gcc treat the following as data only if a global initialization like the
 * above line occurs.
 */

asm(".long 0x534F4434");
asm(ASM_BUILD_DATE);
/* a valid executable file for grub4dos must end with these 8 bytes */
asm(".long 0x03051805");
asm(".long 0xBCBAA7BA");

/* thank goodness gcc will place the above 8 bytes at the end of the b.out
 * file. Do not insert any other asm lines here.
 */
 
 #define FB_MENU_ADDR	0xff0000

#define FB_MAGIC	"FBBF"
#define FB_MAGIC_LONG	0x46424246

#define FB_AR_MAGIC		"FBAR"
#define FB_AR_MAGIC_LONG	0x52414246

#define FBM_TYPE_FILE	1

#define uchar	unsigned char
#define uchar2	unsigned short
#define uchar4	unsigned long

struct fb_mbr
{
  uchar jmp_code;
  uchar jmp_ofs;
  uchar boot_code[0x1ab];
  uchar max_sec;		/* 0x1ad  */
  uchar2 lba;			/* 0x1ae  */
  uchar spt;			/* 0x1b0  */
  uchar heads;			/* 0x1b1  */
  uchar2 boot_base;		/* 0x1b2  */
  uchar4 fb_magic;		/* 0x1b4  */
  uchar mbr_table[0x46];	/* 0x1b8  */
  uchar2 end_magic;		/* 0x1fe  */
} __attribute__((packed));

struct fb_data
{
  uchar2 boot_size;		/* 0x200  */
  uchar2 flags;			/* 0x202  */
  uchar ver_major;		/* 0x204  */
  uchar ver_minor;		/* 0x205  */
  uchar2 list_used;		/* 0x206  */
  uchar2 list_size;		/* 0x208  */
  uchar2 pri_size;		/* 0x20a  */
  uchar4 ext_size;		/* 0x20c  */
} __attribute__((packed));

 
int
main ()
{
	void *p = &main;
	char *arg = p - (*(int *)(p - 8));
	int flags = (*(int *)(p - 12));

struct fb_mbr fbmbr=(*(struct fb_mbr *)0x2000);
struct fb_data fbdata=(*(struct fb_data *)0x2200);

if (fbmbr.fb_magic == FB_MAGIC_LONG) {
printf("boot from: 0x%x\n",fbmbr.lba >> 8);
printf ("version: fbinst %d.%d\n", fbdata.ver_major, fbdata.ver_minor);
printf ("file list size: %d\n", fbdata.list_size*510);
printf ("file list used: %d\n", fbdata.list_used*510);
printf ("primary data size: %dM\n", (fbdata.pri_size + 1024)/2048);
printf ("extended data size:%dM\n", (fbdata.ext_size + 1024)/2048);
}

}
